package com.peng.my_rocketmq.consumer;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.UtilAll;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Service;

import com.peng.my_rocketmq.bean.User;

@Service
@RocketMQMessageListener
(topic = "peng-mq-spring-test", 
selectorExpression = "sendMessOrder",
consumerGroup = "${spring.application.name}-sendMessOrder",
consumeMode = ConsumeMode.ORDERLY)
public class OrderMessageExtConsumer implements RocketMQListener<User> {   

    @Override   

    // 实现消息的消费处理

    public void onMessage(User message) {

        System.out.printf("消费数据------- 用户id:%s, 用户姓名:%s %n ", message.getId(), message.getUsername());   

    }   

   

    // 设置从当前时间点开始消费消息  

/*    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {

        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_TIMESTAMP);       
        consumer.setConsumeTimestamp(UtilAll.timeMillisToHumanString3(System.currentTimeMillis()));   

   }*/

}

